home *** CD-ROM | disk | FTP | other *** search
/ Racing Games (Spidla) / zavodni.iso / Fun Racing / src / FRCar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-19  |  5.5 KB  |  225 lines

  1.  
  2.  
  3. #ifndef FRCAR_H
  4. #define FRCAR_H
  5.  
  6. #include <Engine/Engine.h>
  7.  
  8. typedef struct 
  9. {
  10.     Float fRPMChange;    // RPM change per second if pedal is fully pressed
  11.     Float fRPMTrans;    // Acceleration = fRPMTrans * RPM
  12.  
  13. }FRGearInfo;
  14.  
  15. class FRCarLight;
  16. class FRCarDecal;
  17.  
  18. #define FIRST_GEAR         1
  19. #define SECOND_GEAR         2
  20. #define THIRD_GEAR         3
  21. #define FOURTH_GEAR         4
  22. #define FIFTH_GEAR         5
  23. #define SIXTH_GEAR         6
  24. #define REVERSE_GEAR     0
  25. #define NEUTRAL_GEAR    -1
  26.  
  27. #define MAX_TYRE_DECAL_LENGTH    20.0f
  28. #define MIN_DECAL_SPEED            55.0f
  29.  
  30. #define MAX_LIGHT_SIZE 16.0f
  31. #define MIN_LIGHT_SIZE 6.0f
  32.  
  33. enum FRCarType{AI = 0, LOCAL = 1, NETWORK = 2};
  34. enum FRCarVisibility{NORMAL = 0, INVISIBLE = 1, BLINKING = 2};
  35. enum FRCarState{RACING = 0, FINISHED1ST = 1, FINISHED2ND = 2, FINISHED3RD,
  36. FINISHED4TH = 4, DESTROYED = 5, WAITING = 6, KO = 7};
  37.  
  38. class FRCar : public TEEngineObject
  39. {
  40.     TERTTIDeclaration;
  41.  
  42. public:
  43.  
  44.     FRCar();
  45.  
  46.     ~FRCar();
  47.  
  48.     virtual void Horn(void);
  49.  
  50.     void SetHandbrake(bool bBrake){m_bHandbrake = bBrake;}
  51.     bool GetHandbrake(void){return m_bHandbrake;}
  52.     void SetPedal(Float fPedal);
  53.     Float GetPedal(void){return m_fPedal;}
  54.     void SetSteeringWheel(Float fWheel);
  55.     Float GetSteeringWheel(void){return m_fSteeringWheel;}
  56.  
  57.     Float GetRPM(void){return m_fCurrentRPM;}
  58.     Int32 GetGear(void){return m_lCurrentGear;}
  59.  
  60.     Float GetSpeedKMH(void);
  61.  
  62.     void SetPowerUp(UInt32 lPowerUp);
  63.     void EnablePowerUp(void);
  64.  
  65.     void EMPHit(void);
  66.     void OilHit(void);
  67.  
  68.     TEString m_DriverName;
  69.     UInt32 m_ulAINode;
  70.     UInt32 m_ulLastAINodeChange;
  71.     Float m_fAIEfficiency;
  72.     UInt32 m_ulTrackNode;
  73.     UInt32 m_ulLap;
  74.     bool m_bAIUsesHorn;
  75.     FRCarType m_Type;
  76.     FRCarState m_State;
  77.     FRCarVisibility m_Visibility;
  78.  
  79.     UInt32 m_ulLastReset;
  80.  
  81.     Int32 m_lPowerUp;
  82.     UInt32 m_ulPowerUpEndTime;
  83.     Int32 m_lPowerUpInfluence;
  84.  
  85.     static bool ms_bPowerUpsEnabled;
  86.     static bool ms_bTyreDecals;
  87.     static bool ms_bSmoke;
  88.  
  89. protected:
  90.  
  91.     friend class FRApp;
  92.  
  93.     TESoundReference* m_pPickup;
  94.     TESoundReference* m_pFire;
  95.  
  96.     TESoundReference* m_pMotor;
  97.     TESoundReference* m_pBraking;
  98.     TESoundReference* m_pHorn;
  99.  
  100.     TETextureReference* m_pFrontLight;
  101.     TETextureReference* m_pBackLight;
  102.  
  103.     bool m_bHandbrake;
  104.     Float m_fPedal;            // 1.0f = driving forward  -1.0 = braking
  105.     Float m_fSteeringWheel;    // -1.0f = full left  1.0f = full right
  106.  
  107.     TEVector m_Forward;
  108.     TEVector m_Up;
  109.     TEVector m_Right;
  110.     TEVector m_CarSize;
  111.     Float m_fDeltaY;
  112.  
  113.     Float m_fMaxRPM;
  114.     Float m_fRotFactor;
  115.     UInt32 m_ulNumGears;
  116.     FRGearInfo* m_aGears;
  117.  
  118.     Float m_fCurrentRPM;
  119.     Int32 m_lCurrentGear;
  120.  
  121.     Float m_fFrontAxis;        // Distance from Center to front axis
  122.     Float m_fRearAxis;        // "                     " rear axis
  123.  
  124.     bool m_bBraking;
  125.  
  126.     Float m_fWheelWidth;
  127.     Float m_fWheelMov;
  128.  
  129.     TEVector m_DecalForward;    // stuff for managing tyre decals
  130.     TEVector m_DecalStartLeft;
  131.     TEVector m_DecalStartRight;
  132. //    TEVector m_DecalNormalLeft;
  133. //    TEVector m_DecalNormalRight;
  134.     Float m_fDecalLengthLeft;
  135.     Float m_fDecalLengthRight;
  136.     FRCarDecal* m_pDecalLeft;
  137.     FRCarDecal* m_pDecalRight;
  138.  
  139.     Float m_fBrakeEfficiency;
  140.  
  141.     TEVector m_aLightPos[4];    // Relative position of lights
  142.  
  143.     UInt16 m_usNumExhaust;
  144.     TEParticleFX* m_aExhaust[2];
  145.     TEVector m_aExhaustPos[2];
  146.  
  147.     virtual void Render(TERenderer* pRender, TECamera* pCam);
  148.     virtual void RenderShadow(TERenderer* pRender, TECamera* pCam, TELight* pLights, 
  149.         TEShadowMethod DefaultMethod, bool bMoreThanOneShadow);
  150.     virtual void Animate(UInt32 ulDeltaT, TEEngine* pEngine);
  151.     virtual void Update(UInt32 ulDeltaT, TEEngine* pEngine);
  152.     virtual bool Influence(UInt32 ulDeltaT, TEEngineObject* pObject);
  153.     virtual void OnClip(TEEngineObject* pInfluencer);
  154.  
  155.     void UpdateEngine(UInt32 ulDeltaT, TEEngine* pEngine);
  156.  
  157.     void UpdateVectors(void);
  158.  
  159.     void Reset(TEVector &rCenter, TEVector &rNormal);
  160. private:
  161.  
  162.     void CreateTyreDecals(UInt32 ulDeltaT, TEEngine* pEngine);
  163. };
  164.  
  165. class FRCarDecal : public TEDecal
  166. {
  167. public:
  168.  
  169.     FRCarDecal(TEVector &rPos, TEVector &rForward, Float fLength, Float fWidth)
  170.     {
  171.         TEString Name = "tyre";
  172.         UChar aucColorKey[] = {255, 255, 255};
  173.         
  174.         m_usNumVerts = 6;
  175.         m_aVerts = new TEVertex[6];
  176.         m_pTexture = TETextureManager::GetTextureManager()->GetTexture(Name, Name, false, aucColorKey);
  177.         m_ucAlpha = 220;
  178.         m_bColorKeyed = true;
  179.         m_aucColor[0] = m_aucColor[1] = m_aucColor[2] = 0;
  180.         m_bFadeBeforeDeath = true;
  181.         m_ulFadingStart = 1000;
  182.         m_usSrcBlend = BLEND_SRC_ALPHA;
  183.         m_usDstBlend = BLEND_ONE_MINUS_SRC_ALPHA;
  184.         m_pNext = NULL;
  185.         
  186.         SetData(rPos, rForward, fLength, fWidth);
  187.     }
  188.  
  189.     void SetData(TEVector &rPos, TEVector &rForward, Float fLength, Float fWidth)
  190.     {
  191.         TEVector Vec;
  192.         TEVector Right, Up;
  193.     //    TEVector Normal = TEVector(0.0f, 1.0f, 0.0f);
  194.  
  195.         m_ulCreationTime = TETimer::GetTimer()->GetTime();
  196.         m_ulMaxLifeTime = 30000;
  197.  
  198.     //    Right = Normal.CrossProduct(rForward);
  199.     //    Up = Right.CrossProduct(Normal) * fLength;
  200.         Right = TEVector(rForward.m_fZ, 0.0f, -rForward.m_fX);
  201.         Up = TEVector(rForward.m_fX * fLength, 0.0f, rForward.m_fZ * fLength);
  202.         Right = Right * fWidth * 0.5f;
  203.         
  204.         Vec = rPos - Right + Up;
  205.         m_aVerts[0] = m_aVerts[3] = TEVertex(Vec.m_fX, Vec.m_fY, Vec.m_fZ, 0.0f, 0.0f);
  206.  
  207.         Vec = rPos + Right;
  208.         m_aVerts[1] = m_aVerts[5] = TEVertex(Vec.m_fX, Vec.m_fY, Vec.m_fZ, 1.0f, fLength * 0.5f);
  209.  
  210.         Vec = rPos - Right;
  211.         m_aVerts[2] = TEVertex(Vec.m_fX, Vec.m_fY, Vec.m_fZ, 0.0f, fLength * 0.5f);
  212.  
  213.         Vec = rPos + Right + Up;
  214.         m_aVerts[4] = TEVertex(Vec.m_fX, Vec.m_fY, Vec.m_fZ, 1.0f, 0.0f);
  215.  
  216.         m_Center = rPos;
  217.         
  218.         m_BSphere.UpdateVolume(m_aVerts, m_usNumVerts);
  219.         m_bUseCulling = (m_BSphere.GetVolume() > 200);
  220.     }
  221. };
  222.  
  223. #endif
  224.  
  225.